//===== eAthena Script =======================================
//= ĤG𫰾
//===== By: ==================================================
//= L0ne_W0lf
//===== Current Version: =====================================
//= 2.1
//===== Compatible With: =====================================
//= eAthena SVN
//===== Description: =========================================
//= WoE SE qoow а Castle 2 (woJ)
//============================================================

schg_cas02,1,1,0	script	Manager#sch02_02	111,{
	end;

OnInterIfInitOnce:
	GetCastleData "schg_cas02",0,"::OnRecvCastleSc02";
	end;

OnRecvCastlesc02:
	RequestGuildInfo GetCastleData("schg_cas02",1);
	if (GetCastleData("schg_cas02",1) == 0) {
		donpcevent "Manager#sch02_02::Onstart";
	}
	end;

OnAgitStart2:
	if (agitcheck2()) {
		MapRespawnGuildID "schg_cas02",GetCastleData("schg_cas02",1),2;
		GvgOn "schg_cas02";
		donpcevent "Manager#sch02_02::Onstart";
	}
	else {
		donpcevent "#sch02_RL00::OnDisable";
		donpcevent "#sch02_RL01::OnDisable";
		donpcevent "#sch02_RL02::OnDisable";
		donpcevent "#sch02_RL03::OnDisable";
	}
	end;

OnAgitEnd2:
	GvgOff "schg_cas02";
	if (GetCastleData("schg_cas02",1)) {
		KillMonster "schg_cas02","޲zH#sch02::OnStartArena";
		donpcevent "Manager#sch02_02::Onreset";
		donpcevent "Steward#sch02::Onstop";
	}
	end;

Onstart:
	// 1u@, 2u@, 1mu, 2mu, 3mu, l@H]
	// Settings for all but Summon Guardians
	// 0 = Okay; 1 = Destroyed; 2 = Repairing
	// l@H]
	// 0 = l; 1 = l
	if (GetCastleData("schg_cas02",1)) {
		setarray $agit_sc02[0],0,0,0,0,0,0;
		donpcevent "#sch02_df01::OnEnable";
		donpcevent "#sch02_df02::OnEnable";
		donpcevent "#sch02_RL00::OnEnable";
		donpcevent "#sch02_RL01::OnEnable";
		donpcevent "#sch02_RL02::OnEnable";
		donpcevent "#sch02_RL03::OnEnable";
	}
	monster "schg_cas02",162,193,"R",1288,1,"޲zH#sch02::OnStartArena";
	end;

Onreset:
	donpcevent "#sch02_df01::OnDisable";
	donpcevent "#sch02_df02::OnDisable";
	donpcevent "#sch02_gard01::Onreset";
	donpcevent "#sch02_gard02::Onreset";
	donpcevent "#sch02_RL00::OnDisable";
	donpcevent "#sch02_RL01::OnDisable";
	donpcevent "#sch02_RL02::OnDisable";
	donpcevent "#sch02_RL03::OnDisable";
	donpcevent "1u@#sch02::OnDisable";
	donpcevent "2u@#sch02::OnDisable";
	donpcevent "˸m01#sch02::OnDisable";
	donpcevent "˸m02#sch02::OnDisable";
	donpcevent "˸m03#sch02::OnDisable";
	if (agitcheck2()) {
		setarray $agit_sc02[0],0,0,1,1,1,0;
	}
	end;

Onchange:
	setarray $agit_sc02[0],2,2,1,1,2,0;
	monster "schg_cas02",162,193,"R",1288,1,"޲zH#sch02::OnStartArena";
	donpcevent "˸m03#sch02::OnEnable";
	donpcevent "1u@#sch02::OnEnable";
	donpcevent "2u@#sch02::OnEnable";
	end;

OnClock0001:
	if (!GetCastleData("schg_cas02",1)) end;
	killmonster "schg_cas02","Manager#sch02_02::OnTreasureDied";

	if (GetCastleData("schg_cas02",4)) {
		set .@Economy,GetCastleData("schg_cas02",2);
		SetCastleData "schg_cas02",2,.@Economy + GetCastleData("schg_cas02",4) + (rand(2) && getgdskilllv(.@GID,10014));
		if (GetCastleData("schg_cas02",2) > 100) SetCastleData "schg_cas02",2,100;
		setcastledata "schg_cas02",4,0;
	}
	if (GetCastleData("schg_cas02",5)) {
		set .@Defence,GetCastleData("schg_cas02",3);
		SetCastleData "schg_cas02",3,.@Defence + GetCastleData("schg_cas02",5);
		if (GetCastleData("schg_cas02",3) > 100) SetCastleData "schg_cas02",3,100;
		setcastledata "schg_cas02",5,0;
	}

	set .@Treasure,GetCastleData("schg_cas02",2)/5+4;
	if (.@Treasure) {
		monster "schg_cas02",249,378,"_cl",1939,1,"Manager#sch02_02::OnTreasureDied";
		monster "schg_cas02",250,378,"_cl",1324,1,"Manager#sch02_02::OnTreasureDied";
		monster "schg_cas02",251,378,"_cl",1939,1,"Manager#sch02_02::OnTreasureDied";
		monster "schg_cas02",252,378,"_cl",1324,1,"Manager#sch02_02::OnTreasureDied";
		if (.@Treasure < 5) end;
		monster "schg_cas02",253,378,"_cl",1939,1,"Manager#sch02_02::OnTreasureDied";
		if (.@Treasure < 6) end;
		monster "schg_cas02",246,376,"_cl",1324,1,"Manager#sch02_02::OnTreasureDied";
		if (.@Treasure < 7) end;
		monster "schg_cas02",247,376,"_cl",1939,1,"Manager#sch02_02::OnTreasureDied";
		if (.@Treasure < 8) end;
		monster "schg_cas02",248,376,"_cl",1324,1,"Manager#sch02_02::OnTreasureDied";
		if (.@Treasure < 9) end;
		monster "schg_cas02",249,376,"_cl",1939,1,"Manager#sch02_02::OnTreasureDied";
		if (.@Treasure < 10) end;
		monster "schg_cas02",250,376,"_cl",1324,1,"Manager#sch02_02::OnTreasureDied";
		if (.@Treasure < 11) end;
		monster "schg_cas02",250,374,"_cl",1939,1,"Manager#sch02_02::OnTreasureDied";
		if (.@Treasure < 12) end;
		monster "schg_cas02",251,374,"_cl",1324,1,"Manager#sch02_02::OnTreasureDied";
		if (.@Treasure < 13) end;
		monster "schg_cas02",252,374,"_cl",1939,1,"Manager#sch02_02::OnTreasureDied";
		if (.@Treasure < 14) end;
		monster "schg_cas02",253,374,"_cl",1324,1,"Manager#sch02_02::OnTreasureDied";
		if (.@Treasure < 15) end;
		monster "schg_cas02",246,372,"_cl",1939,1,"Manager#sch02_02::OnTreasureDied";
		if (.@Treasure < 16) end;
		monster "schg_cas02",247,372,"_cl",1324,1,"Manager#sch02_02::OnTreasureDied";
		if (.@Treasure < 17) end;
		monster "schg_cas02",248,372,"_cl",1939,1,"Manager#sch02_02::OnTreasureDied";
		if (.@Treasure < 18) end;
		monster "schg_cas02",249,372,"_cl",1324,1,"Manager#sch02_02::OnTreasureDied";
		if (.@Treasure < 19) end;
		monster "schg_cas02",250,372,"_cl",1939,1,"Manager#sch02_02::OnTreasureDied";
		if (.@Treasure < 20) end;
		monster "schg_cas02",249,370,"_cl",1324,1,"Manager#sch02_02::OnTreasureDied";
		if (.@Treasure < 21) end;
		monster "schg_cas02",250,370,"_cl",1939,1,"Manager#sch02_02::OnTreasureDied";
		if (.@Treasure < 22) end;
		monster "schg_cas02",251,370,"_cl",1324,1,"Manager#sch02_02::OnTreasureDied";
		if (.@Treasure < 23) end;
		monster "schg_cas02",252,270,"_cl",1939,1,"Manager#sch02_02::OnTreasureDied";
		if (.@Treasure < 24) end;
		monster "schg_cas02",253,370,"_cl",1324,1,"Manager#sch02_02::OnTreasureDied";
	}
	end;

OnTreasureDied:
	end;
}

schg_cas02,140,184,3	script	}#sch02_01	868,{
	set .@GID, GetCastleData("schg_cas02",1);
	if (.@GID == 0) {
		mes "[}]";
		mes "\H?";
		mes "ЧA֤@I}oya!";
		close;
	}
	if (getcharid(2) == .@GID) {
		if (strcharinfo(0) != getguildmaster(.@GID)) {
			mes "[}]";
			mes "ڬOtdu@,";
			mes "ԲӪeڷQDH";
			close;
		}
		else {
			if (agitcheck2() == 0) {
				mes "[}]";
				mes "I am Endeef, guardian of";
				mes "this stronghold. For now,";
				mes "all is quiet in this place.";
				next;
				switch(select("Converse:")) {
				case 1:
					mes "[}]";
					mes "Do you have any questions";
					mes "about this stronghold?";
					next;
					switch(select("u@:mu:Ŷʨt:Battle Strategy:")) {
					case 1:
						mes "[}]";
						mes "There is one Emperium";
						mes "and two Guardian Stones in";
						mes "each fortress. These stones";
						mes "are the first line of defense,";
						mes "and must be destroyed before";
						mes "enemies can even enter.";
						next;
						mes "[}]";
						mes "The stones are located in";
						mes "^4D4DFFGate Houses^000000 which must be";
						mes "protected to prevent enemies";
						mes "from reaching the Emperium.";
						mes "Guardian Stones can ^4D4DFFrecall";
						mes "your Guardians^000000 for protection.";
						next;
						mes "[}]";
						mes "Fortresses with higher levels";
						mes "of defense can summon more";
						mes "Guardians: this is why it is";
						mes "so important for guilds to";
						mes "invest in Defense Growth.";
						next;
						mes "[}]";
						mes "Guardian Stones that have";
						mes "been destroyed can be revived";
						mes "after a certain time, but one of^FFFFFF ^000000 the guild members must give";
						mes "me the order. I can also report^FFFFFF ^000000 the status of the Guardian Stones.";
						close;
					case 2:
						mes "[}]";
						mes "^4D4DFFFortress Gates^000000 are the second ^FFFFFF ^000000 line of guild stronghold defense,";
						mes "and are protected by extra barricades activated by the Guardian Stones.";
						mes "These gates are located in three different parts of the fortress.";
						next;
						mes "[}]";
						mes "Barricades are protected by";
						mes "Guardian Stones, and are";
						mes "restored when the Guardian";
						mes "Stones are retrieved. However,";
						mes "it is not as easy to restore";
						mes "destroyed Fortress Gates.";
						next;
						mes "[}]";
						mes "Fortress Gates can only be";
						mes "restored when the ^4D4DFFguild";
						mes "master of a stronghold";
						mes "changes^000000, or if ^4D4DFFrestoration";
						mes "is requested by the guild";
						mes "master of the stronghold^000000.";
						close;
					case 3:
						mes "[}]";
						mes "Strongholds have many";
						mes "Link Flags that allow you";
						mes "to access vital areas within";
						mes "restrictions placed by the";
						mes "Barricades. Usually, ^4D4DFFFlag 1";
						mes "links to the Gate House^000000.";
						next;
						mes "[}]";
						mes "Many flags link directly to";
						mes "the flag near the Emperium.";
						mes "The final numbered flag is";
						mes "linked to the Convenience";
						mes "Facility of the stronghold's";
						mes "owner. Keep this in mind.";
						close;
					case 4:
						mes "[}]";
						mes "Strategy? It would be better";
						mes "to develop your battle plan to";
						mes "exploit your guild's advantages";
						mes "and your enemies' weaknesses.";
						mes "Use the Gate Houses and Barricades, and rebuild as quickly as you can!";
						close;
					case 5:
						mes "[}]";
						mes "You have no questions";
						mes "to ask of me? Well, I'm";
						mes "here to serve your needs.";
						close;
					}
				case 2:
					mes "[}]";
					mes "I'm always here, so";
					mes "feel free to request my";
					mes "assistance whenever";
					mes "the need arises.";
					close;
				}
			}
			else {
				mes "[}]";
				mes "Greetings, "+strcharinfo(0)+".";
				mes "What are your orders?";
				next;
				switch(select("Increase Stronghold Defense:ˬdmA:")) {
				case 1:
					if ($agit_sc02[5] == 0) {
						if (getgdskilllv(.@GID,10002) == 0) {
							mes "[}]";
							mes "I'm sorry, but the Guardian";
							mes "Stones aren't powerful enough";
							mes "to summon Guardians yet. We";
							mes "need to accumulate more";
							mes "knowledge before they can";
							mes "summon any Guardians.";
							close;
						}
						else {
							mes "[}]";
							mes "I shall endeavor to summon";
							mes "a Guardian through a Guardian";
							mes "Stone. However, keep in mind";
							mes "that this will not work if the";
							mes "Guardian Stone is destroyed.";
							setarray $agit_sc02[5],1;
							if ($agit_sc02[0] == 0) {
								donpcevent "#sch02_gard01::OnEnable";
							}
							if ($agit_sc02[1] == 0) {
								donpcevent "#sch02_gard02::OnEnable";
							}
							close;
						}
					}
					else {
						mes "[}]";
						mes "You've already commanded";
						mes "me to summon a Guardian";
						mes "to defend the stronghold.";
						close;
					}
				case 2:
					mes "[}]";
					mes "ڭ̪mAO...";
					if ($agit_sc02[0] == 1) {
						mes "1u@: ^FF0000Q}a^000000";
					}
					else if ($agit_sc02[0] == 2) {
						mes "1u@: ^008000״_^000000";
					}
					else {
						mes "1u@: ^4D4DFF`^000000";
					}
					if ($agit_sc02[1] == 1) {
						mes "2u@: ^FF0000Q}a^000000";
					}
					else if ($agit_sc02[1] == 2) {
						mes "2u@: ^008000״_^000000";
					}
					else {
						mes "2u@: ^4D4DFF`^000000";
					}
					if ($agit_sc02[2] == 1) {
						mes "1mu: ^FF0000Q}a^000000";
					}
					else if ($agit_sc02[2] == 2) {
						mes "1mu: ^008000״_^000000";
					}
					else {
						mes "1mu: ^4D4DFF`^000000";
					}
					if ($agit_sc02[3] == 1) {
						mes "2mu: ^FF0000Q}a^000000";
					}
					else if ($agit_sc02[3] == 2) {
						mes "2mu: ^008000״_^000000";
					}
					else {
						mes "2mu: ^4D4DFF`^000000";
					}
					if ($agit_sc02[4] == 1) {
						mes "3mu: ^FF0000Q}a^000000";
					}
					else if ($agit_sc02[4] == 2) {
						mes "3mu: ^008000״_^000000";
					}
					else {
						mes "3mu: ^4D4DFF`^000000";
					}
					close;
				case 3:
					mes "[}]";
					mes "Hɦb,";
					mes "Աz";
					close;
				}
			}
		}
	}
	else {
		mes "[}]";
		mes "\H?";
		mes "ЧA֤@I}oya!";
		close;
	}

OnInit:
	setarray $agit_sc02[0],0,0,0,0,0,0;
	end;
}

schg_cas02,1,1,0	script	#sch02_gard01	-1,{
OnEnable:
	set .@Defence,GetCastleData("schg_cas02",3);
	guardian "schg_cas02",326,83,"Ch@H]",1899,"#sch02_gard01::OnGuardianDied"; //0;
	if ((.@Defense > 10) && (.@Defense < 31)) {
		set .MyMobCount,2;
		guardian "schg_cas02",337,95,"Ch@H]",1899,"#sch02_gard01::OnGuardianDied"; //1;
	}
	else if ((.@Defense > 30) && (.@Defense < 51)) {
		set .MyMobCount,3;
		guardian "schg_cas02",337,95,"Ch@H]",1899,"#sch02_gard01::OnGuardianDied"; //1;
		guardian "schg_cas02",334,119,"Ch@H]",1899,"#sch02_gard01::OnGuardianDied"; //2;
	}
	else if ((.@Defense > 50) && (.@Defense < 71)) {
		set .MyMobCount,4;
		guardian "schg_cas02",337,95,"Ch@H]",1899,"#sch02_gard01::OnGuardianDied"; //1;
		guardian "schg_cas02",334,119,"Ch@H]",1899,"#sch02_gard01::OnGuardianDied"; //2;
		guardian "schg_cas02",296,82,"Ch@H]",1899,"#sch02_gard01::OnGuardianDied"; //3;
	}
	else if (.@Defense > 70) {
		set .MyMobCount,5;
		guardian "schg_cas02",337,95,"Ch@H]",1899,"#sch02_gard01::OnGuardianDied"; //1;
		guardian "schg_cas02",334,119,"Ch@H]",1899,"#sch02_gard01::OnGuardianDied"; //2;
		guardian "schg_cas02",296,82,"Ch@H]",1899,"#sch02_gard01::OnGuardianDied"; //3;
		guardian "schg_cas02",285,40,"Ch@H]",1899,"#sch02_gard01::OnGuardianDied"; //4;
	}
	else {
		set .MyMobCount,2;
		guardian "schg_cas02",337,95,"Ch@H]",1899,"#sch02_gard01::OnGuardianDied"; //1;
	}
	initnpctimer;
	end;

OnTimer300000:
	set .MyMobCount,.MyMobCount+1;
	guardian "schg_cas02",236,41,"Ch@H]",1899,"#sch02_gard01::OnGuardianDied"; //5;
	mapannounce "schg_cas02","bI 1l[lX@H]F",bc_map,"0xff4500";
	end;

OnTimer900000:
	set .MyMobCount,.MyMobCount+1;
	guardian "schg_cas02",285,40,"Ch@H]",1899,"#sch02_gard01::OnGuardianDied"; //6;
	mapannounce "schg_cas02","bI 2l[lX@H]F",bc_map,"0xff4500";
	end;

OnTimer1800000:
	set .MyMobCount,.MyMobCount+1;
	guardian "schg_cas02",296,82,"Ch@H]",1899,"#sch02_gard01::OnGuardianDied"; //7;
	mapannounce "schg_cas02","bI 3l[lX@H]F",bc_map,"0xff4500";
	end;

OnTimer2700000:
	set .MyMobCount,.MyMobCount+1;
	guardian "schg_cas02",334,119,"Ch@H]",1899,"#sch02_gard01::OnGuardianDied"; //8;
	mapannounce "schg_cas02","bI 4l[lX@H]F",bc_map,"0xff4500";
	end;

OnTimer3600000:
	set .MyMobCount,.MyMobCount+1;
	guardian "schg_cas02",337,95,"Ch@H]",1899,"#sch02_gard01::OnGuardianDied"; //9;
	mapannounce "schg_cas02","bI 5l[lX@H]F",bc_map,"0xff4500";
	stopnpctimer;
	end;

OnGuardianDied:
	set .MyMobCount,.MyMobCount-1;
	if (.MyMobCount < 2) {
		set .MyMobCount,.MyMobCount+1;
		guardian "schg_cas02",334,119,"Ch@H]",1899,"#sch02_gard02::OnGuardianDied"; //10;
	}
	end;

Onreset:
	stopnpctimer;
	killmonster "schg_cas02","#sch02_gard01::OnGuardianDied";
	end;
}

schg_cas02,1,2,0	script	#sch02_gard02	-1,{
OnEnable:
	set .@Defence,GetCastleData("schg_cas02",3);
	guardian "schg_cas02",359,85,"Ch@H]",1899,"#sch02_gard02::OnGuardianDied"; //11;
	if ((.@Defense > 10) && (.@Defense < 31)) {
		set .MyMobCount,2;
		guardian "schg_cas02",300,119,"Ch@H]",1899,"#sch02_gard02::OnGuardianDied"; //12;
	}
	else if ((.@Defense > 30) && (.@Defense < 51)) {
		set .MyMobCount,3;
		guardian "schg_cas02",300,119,"Ch@H]",1899,"#sch02_gard02::OnGuardianDied"; //12;
		guardian "schg_cas02",337,154,"Ch@H]",1899,"#sch02_gard02::OnGuardianDied"; //13;
	}
	else if ((.@Defense > 50) && (.@Defense < 71)) {
		set .MyMobCount,4;
		guardian "schg_cas02",300,119,"Ch@H]",1899,"#sch02_gard02::OnGuardianDied"; //12;
		guardian "schg_cas02",337,154,"Ch@H]",1899,"#sch02_gard02::OnGuardianDied"; //13;
		guardian "schg_cas02",317,183,"Ch@H]",1899,"#sch02_gard02::OnGuardianDied"; //14;
	}
	else if (.@Defense > 70) {
		set .MyMobCount,5;
		guardian "schg_cas02",300,119,"Ch@H]",1899,"#sch02_gard02::OnGuardianDied"; //12;
		guardian "schg_cas02",337,154,"Ch@H]",1899,"#sch02_gard02::OnGuardianDied"; //13;
		guardian "schg_cas02",317,183,"Ch@H]",1899,"#sch02_gard02::OnGuardianDied"; //14;
		guardian "schg_cas02",307,222,"Ch@H]",1899,"#sch02_gard02::OnGuardianDied"; //15;
	}
	else {
		set .MyMobCount,2;
		guardian "schg_cas02",307,222,"Ch@H]",1899,"#sch02_gard02::OnGuardianDied"; //12;
	}
	initnpctimer;
	end;

OnTimer600000:
	set .MyMobCount,.MyMobCount+1;
	guardian "schg_cas02",300,119,"Ch@H]",1899,"#sch02_gard02::OnGuardianDied"; //16;
	end;

OnTimer1200000:
	set .MyMobCount,.MyMobCount+1;
	guardian "schg_cas02",337,154,"Ch@H]",1899,"#sch02_gard02::OnGuardianDied"; //17;
	end;

OnTimer2100000:
	set .MyMobCount,.MyMobCount+1;
	guardian "schg_cas02",317,183,"Ch@H]",1899,"#sch02_gard02::OnGuardianDied"; //18;
	end;

OnTimer3000000:
	set .MyMobCount,.MyMobCount+1;
	guardian "schg_cas02",307,222,"Ch@H]",1899,"#sch02_gard02::OnGuardianDied"; //19;
	end;

OnTimer3900000:
	set .MyMobCount,.MyMobCount+1;
	guardian "schg_cas02",359,85,"Ch@H]",1899,"#sch02_gard02::OnGuardianDied"; //20;
	stopnpctimer;
	end;

OnGuardianDied:
	set .MyMobCount,.MyMobCount-1;
	if (.MyMobCount < 2) {
		set .MyMobCount,.MyMobCount+1;
		guardian "schg_cas02",236,41,"Ch@H]",1899,"#sch02_gard02::OnGuardianDied"; //21;
	}
	end;

Onreset:
	stopnpctimer;
	killmonster "schg_cas02","#sch02_gard02::OnGuardianDied";
	end;
}

schg_cas02,1,3,0	script	#sch02_df01	-1,{
OnEnable:
	guardian "schg_cas02",231,58," 1 u@",1907,"#sch02_df01::OnGuardianStoneDied"; //22;
	end;

OnDisable:
	killmonster "schg_cas02","#sch02_df01::OnGuardianStoneDied";
	setarray $agit_sc02[0],1; //Global Variable
	stopnpctimer;
	end;

OnGuardianStoneDied:
	// 1st Guardian Stone is Destroyed
	setarray $agit_sc02[0],1;
	if (($agit_sc02[0] == 1) || ($agit_sc02[0] == 2)) {
		set .@destroyed,.@destroyed + 1;
	}
	if (($agit_sc02[1] == 1) || ($agit_sc02[1] == 2)) {
		set .@destroyed,.@destroyed + 1;
	}
	if (.@destroyed == 2) {
		mapannounce "schg_cas02","u@ۥ Q}aF!",bc_map,"0x00ff00";
		donpcevent "#sch02_RL00::OnDisable";
		donpcevent "#sch02_gard01::Onreset";
	}
	else {
		mapannounce "schg_cas02","1u@ Q}aF!",bc_map,"0x00ff00";
		donpcevent "#sch02_gard01::Onreset";
	}
	initnpctimer;
	end;

OnTimer300000:
	donpcevent "1u@#sch02::OnEnable";
	setarray $agit_sc02[0],2; //Global Variable
	stopnpctimer;
	end;
}

schg_cas02,231,57,0	script	1u@#sch02	844,{
	set .@GID, GetCastleData("schg_cas02",1);
	if (getcharid(2) == .@GID) {
		mes "}au@ۭnsΦF,";
		mes "YnsΦ pUһݤUCq";
		next;
		mes " 1,";
		mes "T 1,";
		mes "Y 30,";
		mes "Ŧ]Oq 5,";
		mes "]Oq 5,";
		mes "]Oq 5";
		next;
		mes "аݭn~򪺶i@~?";
		switch(select(":i")) {
		case 1:
			mes "Ҧ@~QF";
			close;
		case 2:
			if ((countitem(984) > 0) && (countitem(985) > 0) && (countitem(7049) > 29) && (countitem(717) > 4) && (countitem(715) > 4) && (countitem(716) > 4)) {
				mes "n̾";
				mes "Y,T,ݪǨӰtm,";
				mes "FnsΦ";
				mes "ntm]O]Oq";
				next;
				switch(select("T::Y")) {
				case 1:
					mes "bWT";
					next;
					break;
				case 2:
					mes "bW";
					next;
					break;
				case 3:
					mes "bWY";
					set .@nice,.@nice+10;
					next;
					break;
				}
				switch(select("T::Y")) {
				case 1:
					mes "tmT";
					set .@nice,.@nice+10;
					next;
					break;
				case 2:
					mes "tm";
					next;
					break;
				case 3:
					mes "tmY";
					next;
					break;
				}
				switch(select("T::Y")) {
				case 1:
					mes "Tb̤W";
					next;
					break;
				case 2:
					mes "⯫ݩb̤W";
					set .@nice,.@nice+10;
					next;
					break;
				case 3:
					mes "Yb̤W";
					next;
					break;
				}
				mes "HI]k";
				mes "ntm]O]Oq,";
				mes "]OʽηǳƪĪGHKio";
				next;
				while(1) {
					if (.@roof0 > 7) {
						break;
					}
					else {
						switch(rand(1,3)) {
						case 1:
							specialeffect EF_BEGINSPELL2;
							mes "аtm]O@˪]k";
							mes "]Oqۧa";
							next;
							switch(select("]Oq:]Oq:Ŧ]Oq")) {
							case 1:
								mes "tm]OqۤF";
								close;
							case 2:
								mes "tm]OqۤF,";
								close;
							case 3:
								mes "tmŦ]OqۤF,";
								set .@nice,.@nice+10;
								set .@roof0,.@roof0 + 1;
								specialeffect EF_STEAL;
								next;
								break;
							}
							break;
						case 2:
							specialeffect EF_VOLCANO;
							mes "аtm]O@˪]k";
							mes "]Oqۧa";
							next;
							switch(select("]Oq:]Oq:Ŧ]Oq")) {
							case 1:
								mes "tm]OqۤF";
								set .@nice,.@nice+10;
								set .@roof0,.@roof0 + 1;
								specialeffect EF_STEAL;
								next;
								break;
							case 2:
								mes "tm]OqۤF,";
								close;
							case 3:
								mes "tmŦ]OqۤF,";
								close;
							}
							break;
						case 3:
							specialeffect EF_BEGINSPELL4;
							mes "аtm]O@˪]k";
							mes "]Oqۧa";
							next;
							switch(select("]Oq:]Oq:Ŧ]Oq")) {
							case 1:
								mes "tm]OqۤF";
								mes "of a magic power conflict.^000000";
								close;
							case 2:
								mes "tm]OqۤF,";
								set .@nice,.@nice+10;
								set .@roof0,.@roof0 + 1;
								specialeffect EF_STEAL;
								next;
								break;
							case 3:
								mes "tmŦ]OqۤF,";
								close;
							}
						}
					}
				}
				if (.@nice > 90) {
					if ($agit_sc02[0] == 0) {
						mes "u@ۭsΦwgQF";
						close;
					}
					else {
						if (agitcheck2() == 0) {
							mes "]]O۪Ĭ";
							mes "u@ۭsΦѤF";
							close;
						}
						else {
							mes "wF]Oq۪tm,";
							mes "u@۪sΦO\!!!";
							delitem 984,1; //Oridecon
							delitem 985,1; //Elunium
							delitem 7049,30; //Stone
							delitem 717,5; //Blue_Gemstone
							delitem 715,5; //Yellow_Gemstone
							delitem 716,5; //Red_Gemstone
							close2;
							donpcevent "#sch02_df01::OnEnable";
							specialeffect EF_ICECRASH;
							disablenpc "1u@#sch02";
							setarray $agit_sc02[0],0;
							set .@df_all,$agit_sc02[0]+$agit_sc02[1];
							if (.@df_all == 0) {
								mapannounce "schg_cas02","u@ۤw״_ }ljĵ٤F",bc_map,"0x00ff00";
								donpcevent "#sch02_RL00::OnEnable";
							}
							else {
								mapannounce "schg_cas02","1u@ۭsΦ w\F!",bc_map,"0x00ff00";
							}
							if ($agit_sc02[5] == 1) {
								donpcevent "#sch02_gard01::OnEnable";
							}
							end;
						}
					}
				}
				else {
					mes "Ҧ@~.. ININT";
					mes "S󪺤";
					mes "ݼˤlOѪˤl,";
					mes "hF";
					delitem 7049,10; //Stone
					delitem 717,2; //Blue_Gemstone
					delitem 715,2; //Yellow_Gemstone
					delitem 716,2; //Red_Gemstone
					close;
				}
			}
			else {
				mes "ƨäOܥR";
				close;
			}
		}
	}
	end;

OnInit:
	disablenpc "1u@#sch02";
	end;

OnEnable:
	enablenpc "1u@#sch02";
	specialeffect EF_MAPPILLAR2;
	end;

OnDisable:
	disablenpc "1u@#sch02";
	end;
}

schg_cas02,1,4,0	script	#sch02_df02	-1,{
OnEnable:
	guardian "schg_cas02",335,230," 2 u@",1908,"#sch02_df02::OnGuardianStoneDied"; //23;
	end;

OnDisable:
	killmonster "schg_cas02","#sch02_df02::OnGuardianStoneDied";
	setarray $agit_sc02[1],1; //Global Variable
	stopnpctimer;
	end;

OnGuardianStoneDied:
	// 2nd Guardian Stone is Destroyed
	setarray $agit_sc02[1],1;
	if (($agit_sc02[0] == 1) || ($agit_sc02[0] == 2)) {
		set .@destroyed,.@destroyed + 1;
	}
	if (($agit_sc02[1] == 1) || ($agit_sc02[1] == 2)) {
		set .@destroyed,.@destroyed + 1;
	}
	if (.@destroyed == 2) {
		mapannounce "schg_cas02","u@ۥ Q}aF!",bc_map,"0x00ff00";
		donpcevent "#sch02_RL00::OnDisable";
		donpcevent "#sch02_gard02::Onreset";
	}
	else {
		mapannounce "schg_cas02","2u@ Q}aF!",bc_map,"0x00ff00";
		donpcevent "#sch02_gard02::Onreset";
	}
	initnpctimer;
	end;

OnTimer300000:
	donpcevent "2u@#sch02::OnEnable";
	setarray $agit_sc02[1],2; //Global Variable
	stopnpctimer;
	end;
}

schg_cas02,335,231,0	script	2u@#sch02	844,{
	set .@GID, GetCastleData("schg_cas02",1);
	if (getcharid(2) == .@GID) {
		mes "}au@ۭnsΦF,";
		mes "YnsΦ pUһݤUCq";
		next;
		mes " 1,";
		mes "T 1,";
		mes "Y 30,";
		mes "Ŧ]Oq 5,";
		mes "]Oq 5,";
		mes "]Oq 5";
		next;
		mes "аݭn~򪺶i@~?";
		switch(select(":i")) {
		case 1:
			mes "Ҧ@~QF";
			close;
		case 2:
			if ((countitem(984) > 0) && (countitem(985) > 0) && (countitem(7049) > 29) && (countitem(717) > 4) && (countitem(715) > 4) && (countitem(716) > 4)) {
				mes "n̾";
				mes "Y,T,ݪǨӰtm,";
				mes "FnsΦ";
				mes "ntm]O]Oq";
				next;
				switch(select("T::Y")) {
				case 1:
					mes "bWT";
					next;
					break;
				case 2:
					mes "bW";
					next;
					break;
				case 3:
					mes "bWY";
					set .@nice,.@nice+10;
					next;
					break;
				}
				switch(select("T::Y")) {
				case 1:
					mes "tmT";
					set .@nice,.@nice+10;
					next;
					break;
				case 2:
					mes "tm";
					next;
					break;
				case 3:
					mes "tmY";
					next;
					break;
				}
				switch(select("T::Y")) {
				case 1:
					mes "Tb̤W";
					next;
					break;
				case 2:
					mes "⯫ݩb̤W";
					set .@nice,.@nice+10;
					next;
					break;
				case 3:
					mes "Yb̤W";
					next;
					break;
				}
				mes "HI]k";
				mes "ntm]O]Oq,";
				mes "]OʽηǳƪĪGHKio";
				next;
				while(1) {
					if (.@roof0 > 7) {
						break;
					}
					else {
						switch(rand(1,3)) {
						case 1:
							specialeffect EF_BEGINSPELL2;
							mes "аtm]O@˪]k";
							mes "]Oqۧa";
							next;
							switch(select("]Oq:]Oq:Ŧ]Oq")) {
							case 1:
								mes "tm]OqۤF";
								close;
							case 2:
								mes "tm]OqۤF,";
								close;
							case 3:
								mes "tmŦ]OqۤF,";
								set .@nice,.@nice+10;
								set .@roof0,.@roof0 + 1;
								specialeffect EF_STEAL;
								next;
								break;
							}
							break;
						case 2:
							specialeffect EF_VOLCANO;
							mes "аtm]O@˪]k";
							mes "]Oqۧa";
							next;
							switch(select("]Oq:]Oq:Ŧ]Oq")) {
							case 1:
								mes "tm]OqۤF";
								set .@nice,.@nice+10;
								set .@roof0,.@roof0 + 1;
								specialeffect EF_STEAL;
								next;
								break;
							case 2:
								mes "tm]OqۤF,";
								close;
							case 3:
								mes "tmŦ]OqۤF,";
								close;
							}
							break;
						case 3:
							specialeffect EF_BEGINSPELL4;
							mes "аtm]O@˪]k";
							mes "]Oqۧa";
							next;
							switch(select("]Oq:]Oq:Ŧ]Oq")) {
							case 1:
								mes "tm]OqۤF";
								close;
							case 2:
								mes "tm]OqۤF,";
								set .@nice,.@nice+10;
								set .@roof0,.@roof0 + 1;
								specialeffect EF_STEAL;
								next;
								break;
							case 3:
								mes "tmŦ]OqۤF,";
								close;
							}
						}
					}
				}
				if (.@nice > 90) {
					if ($agit_sc02[1] == 0) {
						mes "u@ۭsΦwgQF";
						close;
					}
					else {
						if (agitcheck2() == 0) {
							mes "]]O۪Ĭ";
							mes "u@ۭsΦѤF";
							close;
						}
						else {
							mes "wg]Oq۪tm,";
							mes "u@۪sΦO\!!!";
							delitem 984,1; //Oridecon
							delitem 985,1; //Elunium
							delitem 7049,30; //Stone
							delitem 717,5; //Blue_Gemstone
							delitem 715,5; //Yellow_Gemstone
							delitem 716,5; //Red_Gemstone
							close2;
							donpcevent "#sch02_df02::OnEnable";
							specialeffect EF_ICECRASH;
							disablenpc "2u@#sch02";
							setarray $agit_sc02[1],0;
							set .@df_all,$agit_sc02[0]+$agit_sc02[1];
							if (.@df_all == 0) {
								mapannounce "schg_cas02","u@ۤw״_ }ljĵ٤F",bc_map,"0x00ff00";
								donpcevent "#sch02_RL00::OnEnable";
							}
							else {
								mapannounce "schg_cas02","2u@ۭsΦ w\F!",bc_map,"0x00ff00";
							}
							if ($agit_sc02[5] == 1) {
								donpcevent "#sch02_gard02::OnEnable";
							}
							end;
						}
					}
				}
				else {
					mes "Ҧ@~.. ININT";
					mes "S󪺤";
					mes "ݼˤlOѪˤl,";
					mes "hF";
					delitem 7049,10; //Stone
					delitem 717,2; //Blue_Gemstone
					delitem 715,2; //Yellow_Gemstone
					delitem 716,2; //Red_Gemstone
					close;
				}
			}
			else {
				mes "ƨäOܥR";
				close;
			}
		}
	}
	end;

OnInit:
	disablenpc "2u@#sch02";
	end;

OnEnable:
	enablenpc "2u@#sch02";
	specialeffect EF_MAPPILLAR2;
	end;

OnDisable:
	disablenpc "2u@#sch02";
	end;
}

schg_cas02,2,1,0	script	#sch02_RL00	-1,{
OnEnable:
	setcell "schg_cas02",290,98,290,105,cell_walkable,0;
	setcell "schg_cas02",290,98,290,105,cell_shootable,0;
	guardian "schg_cas02",290,98," ",1905,"#sch02_RL00::OnBarrierDestroyed"; //24;
	guardian "schg_cas02",290,100," ",1905,"#sch02_RL00::OnBarrierDestroyed"; //25;
	guardian "schg_cas02",290,102," ",1905,"#sch02_RL00::OnBarrierDestroyed"; //26;
	guardian "schg_cas02",290,104," ",1905,"#sch02_RL00::OnBarrierDestroyed"; //27;
	end;

OnDisable:
	setcell "schg_cas02",290,98,290,105,cell_walkable,1;
	setcell "schg_cas02",290,98,290,105,cell_shootable,1;
	killmonster "schg_cas02","#sch02_RL00::OnBarrierDestroyed";
	end;

OnBarrierDestroyed:
	end;
}

schg_cas02,2,2,0	script	#sch02_RL01	-1,{
OnEnable:
	set .MyMobCount,6;
	setcell "schg_cas02",279,98,279,105,cell_walkable,0;
	guardian "schg_cas02",280,98," ",1905,"#sch02_RL01::OnBarrierDestroyed"; //28;
	guardian "schg_cas02",280,100," ",1905,"#sch02_RL01::OnBarrierDestroyed"; //29;
	guardian "schg_cas02",280,102," ",1905,"#sch02_RL01::OnBarrierDestroyed"; //30;
	guardian "schg_cas02",281,99," ",1905,"#sch02_RL01::OnBarrierDestroyed"; //31;
	guardian "schg_cas02",281,101," ",1905,"#sch02_RL01::OnBarrierDestroyed"; //32;
	guardian "schg_cas02",281,103," ",1905,"#sch02_RL01::OnBarrierDestroyed"; //33;
	end;

OnBarrierDestroyed:
	set .MyMobCount,.MyMobCount-1;
	if (.MyMobCount == 0) {
		setarray $agit_sc02[2],1;
		mapannounce "schg_cas02","1mu Q}F",bc_map,"0x00ff00";
		setcell "schg_cas02",279,98,279,105,cell_walkable,1;
	}
	end;

OnDisable:
	setcell "schg_cas02",279,98,279,105,cell_walkable,1;
	killmonster "schg_cas02","#sch02_RL01::OnBarrierDestroyed";
	end;
}

schg_cas02,2,3,0	script	#sch02_RL02	-1,{
OnEnable:
	set .MyMobCount,6;
	setcell "schg_cas02",230,213,230,218,cell_walkable,0;
	guardian "schg_cas02",231,214," ",1905,"#sch02_RL02::OnBarrierDestroyed"; //34;
	guardian "schg_cas02",231,216," ",1905,"#sch02_RL02::OnBarrierDestroyed"; //35;
	guardian "schg_cas02",231,218," ",1905,"#sch02_RL02::OnBarrierDestroyed"; //36;
	guardian "schg_cas02",232,213," ",1905,"#sch02_RL02::OnBarrierDestroyed"; //37;
	guardian "schg_cas02",232,215," ",1905,"#sch02_RL02::OnBarrierDestroyed"; //38;
	guardian "schg_cas02",232,217," ",1905,"#sch02_RL02::OnBarrierDestroyed"; //39;
	end;

OnBarrierDestroyed:
	set .MyMobCount,.MyMobCount-1;
	if (.MyMobCount == 0) {
		setarray $agit_sc02[3],1;
		mapannounce "schg_cas02","2mu Q}F",bc_map,"0x00ff00";
		setcell "schg_cas02",230,213,230,218,cell_walkable,1;
	}
	end;

OnDisable:
	setcell "schg_cas02",230,213,230,218,cell_walkable,1;
	killmonster "schg_cas02","#sch02_RL02::OnBarrierDestroyed";
	end;
}

schg_cas02,2,4,0	script	#sch02_RL03	-1,{
OnEnable:
	set .MyMobCount,4;
	setcell "schg_cas02",160,141,165,141,cell_walkable,0;
	guardian "schg_cas02",160,140," ",1905,"#sch02_RL03::OnBarrierDestroyed"; //40;
	guardian "schg_cas02",162,140," ",1905,"#sch02_RL03::OnBarrierDestroyed"; //41;
	guardian "schg_cas02",164,140," ",1905,"#sch02_RL03::OnBarrierDestroyed"; //42;
	guardian "schg_cas02",166,140," ",1905,"#sch02_RL03::OnBarrierDestroyed"; //43;
	end;

OnBarrierDestroyed:
	set .MyMobCount,.MyMobCount-1;
	if (.MyMobCount == 0) {
		setarray $agit_sc02[4],1;
		mapannounce "schg_cas02","3mu Q}F!!",bc_map,"0x00ff00";
		setcell "schg_cas02",160,141,165,141,cell_walkable,1;
	}
	end;

OnDisable:
	setcell "schg_cas02",160,141,165,141,cell_walkable,1;
	killmonster "schg_cas02","#sch02_RL03::OnBarrierDestroyed";
	end;
}

schg_cas02,288,97,0	script	˸m01#sch02	111,{
	set .@GID, GetCastleData("schg_cas02",1);
	if (getcharid(2) == .@GID) {
		if (strcharinfo(0) == getguildmaster(.@GID)) {
			if ($agit_sc02[2] == 2) {
				mes "^3355FFDemolished Fortress";
				mes "Gates can be repaired,";
				mes "but you will need to gather";
				mes "the following materials.^000000";
				next;
				mes "K 10,";
				mes "K 30,";
				mes "jƪZ-żƤG 5,";
				mes " 10";
				next;
				select("Continue");
				if ((countitem(1019) > 29) && (countitem(999) > 9) && (countitem(1011) > 9) && (countitem(984) > 4)) {
					mes "^3355FFYou will need Trunks to";
					mes "repair the support frame,";
					mes "Oridecon to enhance the";
					mes "gate's endurance, and";
					mes "Emveretarcon to basically";
					mes "hold everything together.^000000";
					next;
					set .@ro_of01,rand(10,15);
					while(1) {
						if (.@ro_of02 == .@ro_of01) {
							break;
						}
						else {
							switch(rand(1,4)) {
							case 1:
								mes "^3355FFThe support frame";
								mes "is badly damaged:";
								mes "fixing this part";
								mes "is a top priority.^000000";
								next;
								switch(select("K:K:jƪZ-żƤG:")) {
								case 1:
									mes "^3355FFThe frame has been";
									mes "reinforced with wood.^000000";
									set .@rp_temp,.@rp_temp + 1;
									set .@ro_of02,.@ro_of02 + 1;
									specialeffect2 EF_REPAIRWEAPON;
									next;
									break;
								case 2:
									mes "^3355FFYou tried using steel,";
									mes "but it's not working very";
									mes "well. You'll have to try";
									mes "something else.^000000";
									close;
								case 3:
									mes "^3355FFYou tried using emveretarcon,";
									mes "but it's not working very well.^FFFFFF ^3355FF You'll have to try something else.";
									close;
								case 4:
									mes "^3355FFYou tried using oridecon,";
									mes "but it's not working very";
									mes "well. You'll have to try";
									mes "something else.^000000";
									close;
								}
								break;
							case 2:
								mes "^3355FFIt looks like the gate's";
								mes "overall endurance needs to";
								mes "be reinforced with something.^000000";
								next;
								switch(select("K:K:jƪZ-żƤG:")) {
								case 1:
									mes "^3355FFYou tried using wood";
									mes "to reinforce the gate.^000000";
									set .@ro_of02,.@ro_of02 + 1;
									next;
									break;
								case 2:
									mes "^3355FFYou tried using steel";
									mes "to reinforce the gate, but";
									mes "it's not working well at all.";
									mes "You'll have to start over.^000000";
									close;
								case 3:
									mes "^3355FFYou tried using emveretarcon";
									mes "to reinforce the gate, but it's";
									mes "not working well at all.";
									mes "You'll have to start over.^000000";
									close;
								case 4:
									mes "^3355FFYou hammered the";
									mes "oridecon: it looks";
									mes "like this will work.^000000";
									set .@rp_temp,.@rp_temp + 1;
									set .@ro_of02,.@ro_of02 + 1;
									specialeffect2 EF_REPAIRWEAPON;
									next;
									break;
								}
								break;
							case 3:
								mes "^3355FFThe damage to the gate";
								mes "has caused all these";
								mes "cracks. You'll have to";
								mes "weld them solid somehow.^000000";
								next;
								switch(select("K:K:jƪZ-żƤG:")) {
								case 1:
									mes "^3355FFYou tried using wood to fix";
									mes "this problem, but it seems";
									mes "to have made it worse.";
									mes "You'll have to start all over.^000000";
									close;
								case 2:
									mes "^3355FFYou used steel to weld";
									mes "all the cracks: the gate is";
									mes "is starting to look more solid.^000000";
									set .@rp_temp,.@rp_temp + 1;
									set .@ro_of02,.@ro_of02 + 1;
									specialeffect2 EF_REPAIRWEAPON;
									next;
									break;
								case 3:
									mes "^3355FFYou tried using emveretarcon";
									mes "to reinforce the gate, but it's";
									mes "not working well at all.";
									mes "You'll have to start over.^000000";
									close;
								case 4:
									mes "^3355FFYou tried using oridecon,";
									mes "but it's not working very";
									mes "well. You'll have to try";
									mes "something else.^000000";
									close;
								}
								break;
							case 4:
								mes "^3355FFNow you need to make";
								mes "sure that the gate is held";
								mes "together pretty solidly.^000000";
								next;
								switch(select("K:K:jƪZ-żƤG:")) {
								case 1:
									mes "^3355FFYou tried using wood to fix";
									mes "this problem, but it seems";
									mes "to have made it worse.";
									mes "You'll have to start all over.^000000";
									close;
								case 2:
									mes "^3355FFYou tried using steel,";
									mes "but it's not working very";
									mes "well. You'll have to try";
									mes "something else.^000000";
									close;
								case 3:
									mes "^3355FFYou successfully used";
									mes "the emveretarcon to repair";
									mes "much of the gate's damage.^000000";
									set .@rp_temp,.@rp_temp + 1;
									set .@ro_of02,.@ro_of02 + 1;
									specialeffect2 EF_REPAIRWEAPON;
									next;
									break;
								case 4:
									mes "^3355FFYou tried using oridecon,";
									mes "but it's not working very";
									mes "well. You'll have to try";
									mes "something else.^000000";
									close;
								}
							}
						}
					}
					mes "^3355FFWell, it looks like";
					mes "you're just about done";
					mes "with repairing the gate.^000000";
					next;
					if (agitcheck2() == 0) {
						mes "^3355FFUnfortunately, the Fortress";
						mes "Gate can't be reconstructed:";
						mes "the Emperium is no longer here.^000000";
						close;
					}
					else {
						if (.@rp_temp == .@ro_of01) {
							mes "^3355FFThe Fortress Gate has";
							mes "been successfully repaired!^000000";
							delitem 1019,30; //Wooden_Block
							delitem 999,10; //Steel
							delitem 1011,10; //Emveretarcon
							delitem 984,5; //Oridecon
							close2;
							donpcevent "#sch02_RL01::OnEnable";
							disablenpc "˸m01#sch02";
							mapannounce "schg_cas02"," 1 mu sظm\F!",bc_map,"0x00ff00";
							setarray $agit_sc02[2],0;
							end;
						}
						else {
							mes "^3355FFThe wall has been breached,";
							mes "and the attempt to repair the";
							mes "Fortress Gate has failed.";
							mes "You lost some of your";
							mes "repair resources...^000000";
							delitem 984,2; //Oridecon
							delitem 999,4; //Steel
							delitem 1019,14; //Wooden_Block
							delitem 1011,3; //Emveretarcon
							close;
						}
					}
				}
				else {
					mes "^3355FFYou can't attempt to repair";
					mes "the Fortress Gate if you don't";
					mes "have all the needed materials.^000000";
					close;
				}
			}
		}
	}
	end;

OnInit:
	disablenpc "˸m01#sch02";
	end;

OnEnable:
	enablenpc "˸m01#sch02";
	end;

OnDisable:
	disablenpc "˸m01#sch02";
	end;
}

schg_cas02,230,209,0	script	˸m02#sch02	111,{
	set .@GID, GetCastleData("schg_cas02",1);
	if (getcharid(2) == .@GID) {
		if (strcharinfo(0) == getguildmaster(.@GID)) {
			if ($agit_sc02[3] == 2) {
				mes "^3355FFDemolished Fortress";
				mes "Gates can be repaired,";
				mes "but you will need to gather";
				mes "the following materials.^000000";
				next;
				mes "K 10,";
				mes "K 30,";
				mes "jƪZ-żƤG 5,";
				mes " 10";
				next;
				select("Continue");
				if ((countitem(1019) > 29) && (countitem(999) > 9) && (countitem(1011) > 9) && (countitem(984) > 4)) {
					mes "^3355FFYou will need Trunks to";
					mes "repair the support frame,";
					mes "Oridecon to enhance the";
					mes "gate's endurance, and";
					mes "Emveretarcon to basically";
					mes "hold everything together.^000000";
					next;
					set .@ro_of01,rand(10,15);
					while(1) {
						if (.@ro_of02 == .@ro_of01) {
							break;
						}
						else {
							switch(rand(1,4)) {
							case 1:
								mes "^3355FFThe support frame";
								mes "is badly damaged:";
								mes "fixing this part";
								mes "is a top priority.^000000";
								next;
								switch(select("K:K:jƪZ-żƤG:")) {
								case 1:
									mes "^3355FFThe frame has been";
									mes "reinforced with wood.^000000";
									set .@rp_temp,.@rp_temp + 1;
									set .@ro_of02,.@ro_of02 + 1;
									specialeffect2 EF_REPAIRWEAPON;
									next;
									break;
								case 2:
									mes "^3355FFYou tried using steel,";
									mes "but it's not working very";
									mes "well. You'll have to try";
									mes "something else.^000000";
									close;
								case 3:
									mes "^3355FFYou tried using emveretarcon";
									mes "to reinforce the gate, but it's";
									mes "not working well at all.";
									mes "You'll have to start over.^000000";
									close;
								case 4:
									mes "^3355FFYou tried using oridecon,";
									mes "but it's not working very";
									mes "well. You'll have to try";
									mes "something else.^000000";
									close;
								}
								break;
							case 2:
								mes "^3355FFIt looks like the gate's";
								mes "overall endurance needs to";
								mes "be reinforced with something.^000000";
								next;
								switch(select("K:K:jƪZ-żƤG:")) {
								case 1:
									mes "^3355FFYou tried using wood";
									mes "to reinforce the gate.^000000";
									set .@ro_of02,.@ro_of02 + 1;
									next;
									break;
								case 2:
									mes "^3355FFYou tried using steel";
									mes "to reinforce the gate, but";
									mes "it's not working well at all.";
									mes "You'll have to start over.^000000";
									close;
								case 3:
									mes "^3355FFYou tried using emveretarcon";
									mes "to reinforce the gate, but it's";
									mes "not working well at all.";
									mes "You'll have to start over.^000000";
									close;
								case 4:
									mes "^3355FFYou hammered the";
									mes "oridecon: it looks";
									mes "like this will work.^000000";
									set .@rp_temp,.@rp_temp + 1;
									set .@ro_of02,.@ro_of02 + 1;
									specialeffect2 EF_REPAIRWEAPON;
									next;
									break;
								}
								break;
							case 3:
								mes "^3355FFThe damage to the gate";
								mes "has caused all these";
								mes "cracks. You'll have to";
								mes "weld them solid somehow.^000000";
								next;
								switch(select("K:K:jƪZ-żƤG:")) {
								case 1:
									mes "^3355FFYou tried using wood to fix";
									mes "this problem, but it seems";
									mes "to have made it worse.";
									mes "You'll have to start all over.^000000";
									close;
								case 2:
									mes "^3355FFYou used steel to weld";
									mes "all the cracks: the gate is";
									mes "is starting to look more solid.^000000";
									set .@rp_temp,.@rp_temp + 1;
									set .@ro_of02,.@ro_of02 + 1;
									specialeffect2 EF_REPAIRWEAPON;
									next;
									break;
								case 3:
									mes "^3355FFYou tried using emveretarcon";
									mes "to reinforce the gate, but it's";
									mes "not working well at all.";
									mes "You'll have to start over.^000000";
									close;
								case 4:
									mes "^3355FFYou tried using oridecon,";
									mes "but it's not working very";
									mes "well. You'll have to try";
									mes "something else.^000000";
									close;
								}
								break;
							case 4:
								mes "^3355FFNow you need to make";
								mes "sure that the gate is held";
								mes "together pretty solidly.^000000";
								next;
								switch(select("K:K:jƪZ-żƤG:")) {
								case 1:
									mes "^3355FFYou tried using wood to fix";
									mes "this problem, but it seems";
									mes "to have made it worse.";
									mes "You'll have to start all over.^000000";
									close;
								case 2:
									mes "^3355FFYou tried using steel,";
									mes "but it's not working very";
									mes "well. You'll have to try";
									mes "something else.^000000";
									close;
								case 3:
									mes "^3355FFYou successfully used";
									mes "the emveretarcon to repair";
									mes "much of the gate's damage.^000000";
									set .@rp_temp,.@rp_temp + 1;
									set .@ro_of02,.@ro_of02 + 1;
									specialeffect2 EF_REPAIRWEAPON;
									next;
									break;
								case 4:
									mes "^3355FFYou tried using oridecon,";
									mes "but it's not working very";
									mes "well. You'll have to try";
									mes "something else.^000000";
									close;
								}
							}
						}
					}
					mes "^3355FFWell, it looks like";
					mes "you're just about done";
					mes "with repairing the gate.^000000";
					next;
					if (agitcheck2() == 0) {
						mes "^3355FFUnfortunately, the Fortress";
						mes "Gate can't be reconstructed:";
						mes "the Emperium is no longer here.^000000";
						close;
					}
					else {
						if (.@rp_temp == .@ro_of01) {
							mes "^3355FFThe Fortress Gate has";
							mes "been successfully repaired!^000000";
							delitem 1019,30; //Wooden_Block
							delitem 999,10; //Steel
							delitem 1011,10; //Emveretarcon
							delitem 984,5; //Oridecon
							close2;
							donpcevent "#sch02_RL02::OnEnable";
							disablenpc "˸m02#sch02";
							mapannounce "schg_cas02"," 2 mu sظm\F!",bc_map,"0x00ff00";
							setarray $agit_sc02[3],0; //Global Variable
							setarray $agit_sc02[2],2; //Global Variable
							donpcevent "˸m01#sch02::OnEnable";
							end;
						}
						else {
							mes "^3355FFThe wall has been breached,";
							mes "and the attempt to repair the";
							mes "Fortress Gate has failed.";
							mes "You lost some of your";
							mes "repair resources...^000000";
							delitem 984,2; //Oridecon
							delitem 999,4; //Steel
							delitem 1019,14; //Wooden_Block
							delitem 1011,3; //Emveretarcon
							close;
						}
					}
				}
				else {
					mes "^3355FFYou can't attempt to repair";
					mes "the Fortress Gate if you don't";
					mes "have all the needed materials.^000000";
					close;
				}
			}
		}
	}
	end;

OnInit:
	disablenpc "˸m02#sch02";
	end;

OnEnable:
	enablenpc "˸m02#sch02";
	end;

OnDisable:
	disablenpc "˸m02#sch02";
	end;
}

schg_cas02,159,143,0	script	˸m03#sch02	111,{
	set .@GID, GetCastleData("schg_cas02",1);
	if (getcharid(2) == .@GID) {
		if (strcharinfo(0) == getguildmaster(.@GID)) {
			if ($agit_sc02[4] == 2) {
				mes "^3355FFDemolished Fortress";
				mes "Gates can be repaired,";
				mes "but you will need to gather";
				mes "the following materials.^000000";
				next;
				mes "K 10,";
				mes "K 30,";
				mes "jƪZ-żƤG 5,";
				mes " 10";
				next;
				select("Continue");
				if ((countitem(1019) > 29) && (countitem(999) > 9) && (countitem(1011) > 9) && (countitem(984) > 4)) {
					mes "^3355FFYou will need Trunks to";
					mes "repair the support frame,";
					mes "Oridecon to enhance the";
					mes "gate's endurance, and";
					mes "Emveretarcon to basically";
					mes "hold everything together.^000000";
					next;
					set .@ro_of01,rand(10,15);
					while(1) {
						if (.@ro_of02 == .@ro_of01) {
							break;
						}
						else {
							switch(rand(1,4)) {
							case 1:
								mes "^3355FFThe support frame";
								mes "is badly damaged:";
								mes "fixing this part";
								mes "is a top priority.^000000";
								next;
								switch(select("K:K:jƪZ-żƤG:")) {
								case 1:
									mes "^3355FFThe frame has been";
									mes "reinforced with wood.^000000";
									set .@rp_temp,.@rp_temp + 1;
									set .@ro_of02,.@ro_of02 + 1;
									specialeffect2 EF_REPAIRWEAPON;
									next;
									break;
								case 2:
									mes "^3355FFYou tried using steel,";
									mes "but it's not working very";
									mes "well. You'll have to try";
									mes "something else.^000000";
									close;
								case 3:
									mes "^3355FFYou tried using emveretarcon";
									mes "to reinforce the gate, but it's";
									mes "not working well at all.";
									mes "You'll have to start over.^000000";
									close;
								case 4:
									mes "^3355FFYou tried using oridecon,";
									mes "but it's not working very";
									mes "well. You'll have to try";
									mes "something else.^000000";
									close;
								}
								break;
							case 2:
								mes "^3355FFIt looks like the gate's";
								mes "overall endurance needs to";
								mes "be reinforced with something.^000000";
								next;
								switch(select("K:K:jƪZ-żƤG:")) {
								case 1:
									mes "^3355FFYou tried using wood";
									mes "to reinforce the gate.^000000";
									set .@ro_of02,.@ro_of02 + 1;
									next;
									break;
								case 2:
									mes "^3355FFYou tried using steel";
									mes "to reinforce the gate, but";
									mes "it's not working well at all.";
									mes "You'll have to start over.^000000";
									close;
								case 3:
									mes "^3355FFYou tried using emveretarcon";
									mes "to reinforce the gate, but it's";
									mes "not working well at all.";
									mes "You'll have to start over.^000000";
									close;
								case 4:
									mes "^3355FFYou hammered the";
									mes "oridecon: it looks";
									mes "like this will work.^000000";
									set .@rp_temp,.@rp_temp + 1;
									set .@ro_of02,.@ro_of02 + 1;
									specialeffect2 EF_REPAIRWEAPON;
									next;
									break;
								}
								break;
							case 3:
								mes "^3355FFThe damage to the gate";
								mes "has caused all these";
								mes "cracks. You'll have to";
								mes "weld them solid somehow.^000000";
								next;
								switch(select("K:K:jƪZ-żƤG:")) {
								case 1:
									mes "^3355FFYou tried using wood to fix";
									mes "this problem, but it seems";
									mes "to have made it worse.";
									mes "You'll have to start all over.^000000";
									close;
								case 2:
									mes "^3355FFYou used steel to weld";
									mes "all the cracks: the gate is";
									mes "is starting to look more solid.^000000";
									set .@rp_temp,.@rp_temp + 1;
									set .@ro_of02,.@ro_of02 + 1;
									specialeffect2 EF_REPAIRWEAPON;
									next;
									break;
								case 3:
									mes "^3355FFYou tried using emveretarcon";
									mes "to reinforce the gate, but it's";
									mes "not working well at all.";
									mes "You'll have to start over.^000000";
									close;
								case 4:
									mes "^3355FFYou tried using oridecon,";
									mes "but it's not working very";
									mes "well. You'll have to try";
									mes "something else.^000000";
									close;
								}
								break;
							case 4:
								mes "^3355FFNow you need to make";
								mes "sure that the gate is held";
								mes "together pretty solidly.^000000";
								next;
								switch(select("K:K:jƪZ-żƤG:")) {
								case 1:
									mes "^3355FFYou tried using wood to fix";
									mes "this problem, but it seems";
									mes "to have made it worse.";
									mes "You'll have to start all over.^000000";
									close;
								case 2:
									mes "^3355FFYou tried using steel,";
									mes "but it's not working very";
									mes "well. You'll have to try";
									mes "something else.^000000";
									close;
								case 3:
									mes "^3355FFYou successfully used";
									mes "the emveretarcon to repair";
									mes "much of the gate's damage.^000000";
									set .@rp_temp,.@rp_temp + 1;
									set .@ro_of02,.@ro_of02 + 1;
									specialeffect2 EF_REPAIRWEAPON;
									next;
									break;
								case 4:
									mes "^3355FFYou tried using oridecon,";
									mes "but it's not working very";
									mes "well. You'll have to try";
									mes "something else.^000000";
									close;
								}
							}
						}
					}
					mes "^3355FFWell, it looks like";
					mes "you're just about done";
					mes "with repairing the gate.^000000";
					next;
					if (agitcheck2() == 0) {
						mes "^3355FFUnfortunately, the Fortress";
						mes "Gate can't be reconstructed:";
						mes "the Emperium is no longer here.^000000";
						close;
					}
					else {
						if (.@rp_temp == .@ro_of01) {
							mes "^3355FFThe Fortress Gate has";
							mes "been successfully repaired!^000000";
							delitem 1019,30; //Wooden_Block
							delitem 999,10; //Steel
							delitem 1011,10; //Emveretarcon
							delitem 984,5; //Oridecon
							close;
							donpcevent "#sch02_RL03::OnEnable";
							disablenpc "˸m03#sch02";
							mapannounce "schg_cas02"," 3 mu sظm\F!",bc_map,"0x00ff00";
							setarray $agit_sc02[4],0;
							setarray $agit_sc02[3],2;
							donpcevent "˸m02#sch02::OnEnable";
							end;
						}
						else {
							mes "^3355FFThe wall has been breached,";
							mes "and the attempt to repair the";
							mes "Fortress Gate has failed.";
							mes "You lost some of your";
							mes "repair resources...^000000";
							delitem 984,2; //Oridecon
							delitem 999,4; //Steel
							delitem 1019,14; //Wooden_Block
							delitem 1011,3; //Emveretarcon
							close;
						}
					}
				}
				else {
					mes "^3355FFYou can't attempt to repair";
					mes "the Fortress Gate if you don't";
					mes "have all the needed materials.^000000";
					close;
				}
			}
		}
	}
	end;

OnInit:
	disablenpc "˸m03#sch02";
	end;

OnEnable:
	enablenpc "˸m03#sch02";
	end;

OnDisable:
	disablenpc "˸m03#sch02";
	end;
}

// Link Flags
schg_cas02,143,198,0	script	LF-01#schg_cas02	111,{
	set .@GID, GetCastleData("schg_cas02",1);
	if (getcharid(2) == .@GID) {
		mes "-Ka Ŷʨt-";
		mes "пܭnʪ";
		switch(select(" 1 I: 2 I:")) {
		case 1:
			warp "schg_cas02",235,44;
			end;
		case 2:
			warp "schg_cas02",302,233;
			end;
		case 3:
			close;
		}
	}
	end;
}

schg_cas02,143,202,0	script	LF-02#schg_cas02	111,{
	set .@GID, GetCastleData("schg_cas02",1);
	if (getcharid(2) == .@GID) {
		mes "-Ka Ŷʨt-";
		mes "пܭnʪ";
		switch(select("ma 1-1:ma 1-2:")) {
		case 1:
			warp "schg_cas02",317,83;
			end;
		case 2:
			warp "schg_cas02",359,83;
			end;
		case 3:
			close;
		}
	}
	end;
}

schg_cas02,143,206,0	script	LF-03#schg_cas02	111,{
	set .@GID, GetCastleData("schg_cas02",1);
	if (getcharid(2) == .@GID) {
		mes "-Ka Ŷʨt-";
		mes "пܭnʪ";
		switch(select("ma 2-1:ma 2-2:")) {
		case 1:
			warp "schg_cas02",283,79;
			end;
		case 2:
			warp "schg_cas02",280,122;
			end;
		case 3:
			close;
		}
	}
	end;
}

schg_cas02,145,208,0	script	LF-04#schg_cas02	111,{
	set .@GID, GetCastleData("schg_cas02",1);
	if (getcharid(2) == .@GID) {
		mes "-Ka Ŷʨt-";
		mes "пܭnʪ";
		switch(select("ma 3-1:ma 3-2:")) {
		case 1:
			warp "schg_cas02",215,110;
			end;
		case 2:
			warp "schg_cas02",255,215;
			end;
		case 3:
			close;
		}
	}
	end;
}

schg_cas02,180,208,0	script	LF-05#schg_cas02	111,{
	set .@GID, GetCastleData("schg_cas02",1);
	if (getcharid(2) == .@GID) {
		mes "-Ka Ŷʨt-";
		mes "пܭnʪ";
		switch(select("a 1:a 2:")) {
		case 1:
			warp "schg_cas02",338,153;
			end;
		case 2:
			warp "schg_cas02",213,226;
			end;
		case 3:
			close;
		}
	}
	end;
}

schg_cas02,182,206,0	script	LF-06#schg_cas02	111,{
	set .@GID, GetCastleData("schg_cas02",1);
	if (getcharid(2) == .@GID) {
		mes "-Ka Ŷʨt-";
		mes "пܭnʪ";
		switch(select("ϰ 1-1:ϰ 2-1:ϰ 3-1:")) {
		case 1:
			warp "schg_cas02",317,83;
			end;
		case 2:
			warp "schg_cas02",283,79;
			end;
		case 3:
			warp "schg_cas02",215,110;
			end;
		case 4:
			close;
		}
	}
	end;
}

schg_cas02,182,202,0	script	LF-07#schg_cas02	111,{
	set .@GID, GetCastleData("schg_cas02",1);
	if (getcharid(2) == .@GID) {
		mes "-Ka Ŷʨt-";
		mes "пܭnʪ";
		switch(select("ϰ 1-2:ϰ 2-2:ϰ 3-2:")) {
		case 1:
			warp "schg_cas02",359,83;
			end;
		case 2:
			warp "schg_cas02",280,122;
			end;
		case 3:
			warp "schg_cas02",255,215;
			end;
		case 4:
			close;
		}
	}
	end;
}

schg_cas02,182,198,0	script	LF-08#schg_cas02	111,{
	set .@GID, GetCastleData("schg_cas02",1);
	if (getcharid(2) == .@GID) {
		mes "-Ka Ŷʨt-";
		mes "iHʨ쬰F|̪KQҧΦϰ,";
		mes "аݧAnʶ?";
		switch(select("ʨKQϰ:")) {
		case 1:
			warp "schg_cas02",101,306;
			end;
		case 2:
			close;
		}
	}
	end;
}

schg_cas02,235,222,0	script	woJ#LF_sc02_1::LF_sc02_1	111,{
	set .@GID, GetCastleData("schg_cas02",1);
	if (getcharid(2) == .@GID) {
		mes "-Ka Ŷʨt-";
		mes "ʨ즳RݤԲa,";
		mes "аݧAnϥζ?";
		switch(select(":")) {
		case 1:
			warp "schg_cas02",136,188;
			end;
		case 2:
			close;
		}
	}
	end;
}

schg_cas02,157,136,0	duplicate(LF_sc02_1)	woJ#LF_sc02_2	111
schg_cas02,168,136,4	duplicate(LF_sc02_1)	woJ#LF_sc02_3	111
schg_cas02,320,232,4	duplicate(LF_sc02_1)	woJ#LF_sc02_4	111
schg_cas02,295,109,0	duplicate(LF_sc02_1)	woJ#LF_sc02_5	111
schg_cas02,295,92,0	duplicate(LF_sc02_1)	woJ#LF_sc02_6	111
schg_cas02,285,90,4	duplicate(LF_sc02_1)	woJ#LF_sc02_7	111
schg_cas02,285,190,4	duplicate(LF_sc02_1)	woJ#LF_sc02_8	111
schg_cas02,238,66,0	duplicate(LF_sc02_1)	woJ#LF_sc02_9	111
schg_cas02,230,45,0	duplicate(LF_sc02_1)	woJ#LF_sc02_10	111
schg_cas02,233,120,0	duplicate(LF_sc02_1)	woJ#LF_sc02_11	111
schg_cas02,247,120,0	duplicate(LF_sc02_1)	woJ#LF_sc02_12	111
schg_cas02,261,162,0	duplicate(LF_sc02_1)	woJ#LF_sc02_13	111
schg_cas02,244,162,0	duplicate(LF_sc02_1)	woJ#LF_sc02_14	111
schg_cas02,235,207,0	duplicate(LF_sc02_1)	woJ#LF_sc02_15	111

// Guild Manager
schg_cas02,105,378,3	script	޲zH#sch02	55,{
	set .@GID, GetCastleData("schg_cas02",1);
	if (.@GID == 0) {
		mes "[ ޲zH ]";
		mes "ڦbݧڪDH... i_Ḭ! lHARBa!";
		close;
	}
	if (getcharid(2) != .@GID || strcharinfo(0) != getguildmaster(.@GID)) {
		mes "[ ޲zH ]";
		mes "ާA̫¯٧,ڥu@NlHڪDH ^FF0000" + getguildmaster(.@GID) + "^000000 !";
		mes "@HA̦b̧r!";
		mes "֧oǵLzå̻a!";
		close;
	}
	mes "[ ޲zH ]";
	mes "w{,ڪDH ^FF0000" + getguildmaster(.@GID) + "^000000/pj...";
	mes "оާhJ,ڱNۦaA";
	next;
	switch(select("dݯKap:ӷ~oi:꨾m: / Ѷ ܮw¾:iJDHж")) {
	case 1:
		mes "[ ޲zH ]";
		mes "The Commercial Growth";
		mes "Level of the stronghold is ^0000ff" + GetCastleData("schg_cas02",2) + " ";
		if (GetCastleData("schg_cas02",4) > 0) {
			mes "bLh@Ѥ,";
			mes "F " + GetCastleData("schg_cas02",4) + "";
		}
		next;
		mes "[ ޲zH ]";
		mes "{bm׬O " + GetCastleData("schg_cas02",3) + " ";
		if (GetCastleData("schg_cas02",5) > 0) {
			mes "bLh@Ѥ,";
			mes "F " + GetCastleData("schg_cas02",5) + " ";
		}
		mes " ";
		mes "i";
		close;
	case 2:
		set .@Economy,GetCastleData("schg_cas02",2);
		if (.@Economy < 6) { set .@eco_invest,5000; }
		else if ((.@Economy >= 6) && (.@Economy <= 10)) { set .@eco_invest,10000; }
		else if ((.@Economy >= 11) && (.@Economy <= 15)) { set .@eco_invest,20000; }
		else if ((.@Economy >= 16) && (.@Economy <= 20)) { set .@eco_invest,35000; }
		else if ((.@Economy >= 21) && (.@Economy <= 25)) { set .@eco_invest,55000; }
		else if ((.@Economy >= 26) && (.@Economy <= 30)) { set .@eco_invest,80000; }
		else if ((.@Economy >= 31) && (.@Economy <= 35)) { set .@eco_invest,110000; }
		else if ((.@Economy >= 36) && (.@Economy <= 40)) { set .@eco_invest,145000; }
		else if ((.@Economy >= 41) && (.@Economy <= 45)) { set .@eco_invest,185000; }
		else if ((.@Economy >= 46) && (.@Economy <= 50)) { set .@eco_invest,230000; }
		else if ((.@Economy >= 51) && (.@Economy <= 55)) { set .@eco_invest,280000; }
		else if ((.@Economy >= 56) && (.@Economy <= 60)) { set .@eco_invest,335000; }
		else if ((.@Economy >= 61) && (.@Economy <= 65)) { set .@eco_invest,395000; }
		else if ((.@Economy >= 66) && (.@Economy <= 70)) { set .@eco_invest,460000; }
		else if ((.@Economy >= 71) && (.@Economy <= 75)) { set .@eco_invest,530000; }
		else if ((.@Economy >= 76) && (.@Economy <= 80)) { set .@eco_invest,605000; }
		else if ((.@Economy >= 81) && (.@Economy <= 85)) { set .@eco_invest,685000; }
		else if ((.@Economy >= 86) && (.@Economy <= 90)) { set .@eco_invest,770000; }
		else if ((.@Economy >= 91) && (.@Economy <= 95)) { set .@eco_invest,860000; }
		else if ((.@Economy >= 96) && (.@Economy <= 100)) { set .@eco_invest,955000; }
		//Quadruple the cost of investing if you've already invested once.
		if (GetCastleData("schg_cas02",4)) {
			set .@eco_invest,.@eco_invest*4;
		}
		mes "[ ޲zH ]";
		mes "ӷ~oiת,bu|̥Ͳ~ƶq|W[,FH۷Q,ण";
		mes " ";
		mes "ӭ覡,@ѥu@,phI@I,@ѥiH⦸";
		mes " ";
		if (.@Economy == 100) {
			mes "^FF0000ثemץHgO100F,AwgݭnA[JF^000000";
			close;
		}
		if (GetCastleData("schg_cas02",4) == 2) {
			mes "^FF0000iOAwgbѤF⦸AF,^000000oi׻֤Wɴݵ۴IQlo";
			close;
		}
		if (GetCastleData("schg_cas02",4) == 0) {
			mes "{bݭnꪺBO ^FF0000" + .@eco_invest + "^000000 ,аݧAn?";
		}
		else {
			mes "{bAwg@F...";
			mes "٭nA? ٻݭnl[^FF0000" + .@eco_invest + "^000000";
			mes "";
		}
		next;
		switch(select("ӷ~oi:")) {
		case 1:
			if (Zeny < .@eco_invest) {
				mes "[ ޲zH ]";
				mes "DH,ASiHӷ~oi";
				end;
			}
			set zeny,zeny-.@eco_invest;
			SetCastleData "schg_cas02",4,GetCastleData("schg_cas02",4)+1;
			mes "[ ޲zH ]";
			mes "QaF!";
			mes "ݵۧڭ̩n{,Ѫܵoi׷|W";
			close;
		case 2:
			mes "[ ޲zH ]";
			mes "ڱN̷ӧAhJh,OڪDH";
			mes "... ݭnӵ۫,ڭ̷|oܦn";
			close;
		}
	case 3:
		set .@Defence,GetCastleData("schg_cas02",3);
		if (.@Defence < 6) { set .@def_invest,10000; }
		else if ((.@Defence >= 6) && (.@Defence <= 10)) { set .@def_invest,20000; }
		else if ((.@Defence >= 11) && (.@Defence <= 15)) { set .@def_invest,40000; }
		else if ((.@Defence >= 16) && (.@Defence <= 20)) { set .@def_invest,70000; }
		else if ((.@Defence >= 21) && (.@Defence <= 25)) { set .@def_invest,110000; }
		else if ((.@Defence >= 26) && (.@Defence <= 30)) { set .@def_invest,160000; }
		else if ((.@Defence >= 31) && (.@Defence <= 35)) { set .@def_invest,220000; }
		else if ((.@Defence >= 36) && (.@Defence <= 40)) { set .@def_invest,290000; }
		else if ((.@Defence >= 41) && (.@Defence <= 45)) { set .@def_invest,370000; }
		else if ((.@Defence >= 46) && (.@Defence <= 50)) { set .@def_invest,460000; }
		else if ((.@Defence >= 51) && (.@Defence <= 55)) { set .@def_invest,560000; }
		else if ((.@Defence >= 56) && (.@Defence <= 60)) { set .@def_invest,670000; }
		else if ((.@Defence >= 61) && (.@Defence <= 65)) { set .@def_invest,790000; }
		else if ((.@Defence >= 66) && (.@Defence <= 70)) { set .@def_invest,920000; }
		else if ((.@Defence >= 71) && (.@Defence <= 75)) { set .@def_invest,1060000; }
		else if ((.@Defence >= 76) && (.@Defence <= 80)) { set .@def_invest,1210000; }
		else if ((.@Defence >= 81) && (.@Defence <= 85)) { set .@def_invest,1370000; }
		else if ((.@Defence >= 86) && (.@Defence <= 90)) { set .@def_invest,1540000; }
		else if ((.@Defence >= 91) && (.@Defence <= 95)) { set .@def_invest,1720000; }
		else if ((.@Defence >= 96) && (.@Defence <= 100)) { set .@def_invest,1910000; }
		//Quadruple the cost of investing if you've already invested once.
		if (GetCastleData("schg_cas02",5)) {
			set .@def_invest,.@def_invest*4;
		}
		mes "[ ޲zH ]";
		mes "m{ת,@HMRݪ@[׷|W[,Ҽ{쩹᪺Ԫ,o,";
		mes " ";
		mes "ӭ覡,@ѥu@,phI@I,@ѥiH⦸";
		mes " ";
		if (GetCastleData("schg_cas02",3) == 100) {
			mes "^FF0000ثemץHgO100F,AwgݭnA[JF^000000";
			close;
		}
		if (GetCastleData("schg_cas02",5) == 2) {
			mes "^FF0000iOAwgbѤF⦸AF,^000000oi׻֤Wɴݵ۴IQlo";
			close;
		}
		next;
		mes "[ ޲zH ]";
		if (GetCastleData("schg_cas02",5) == 0) {
			mes "{bݭnꪺBO ^FF0000" + .@def_invest + "^000000 ,аݧAn?";
		}
		else {
			mes "{bAwg@F...";
			mes "٭nA? ٻݭnl[ ^FF0000" + .@def_invest + "^000000";
			mes "";
		}
		next;
		switch(select("꨾m:")) {
		case 1:
			if (Zeny < .@def_invest) {
				mes "[ ޲zH ]";
				mes "DH,ASiH꨾m";
				close;
			}
			set zeny,zeny-.@def_invest;
			SetCastleData "schg_cas02",5,GetCastleData("schg_cas02",5)+1;
			mes "[ ޲zH ]";
			mes "QaF!";
			mes "ݵۧڭ̩n{,Ѫܵoi׷|W";
			close;
		case 2:
			mes "[ ޲zH ]";
			mes "ڱN̷ӧAhJh,OڪDH";
			mes "... ݭnӵ۫,ڭ̷|oܦn";
			close;
		}
	case 4:
		if (GetCastleData("schg_cas02",9) == 1) {
			mes "[ ޲zH ]";
			mes "аݱznѶdԪAȤH?";
			next;
			switch(select("Ѷ:")) {
			case 1:
				cutin "kafra_01",2;
				mes "[ d ¾ ]";
				mes "ڰFƶ?pGڦƪ,бz̧,Aڤ@|?";
				next;
				switch(select("Ѷ:")) {
				case 1:
					mes "[ d ¾ ]";
					mes "~򬰱zAȯuOڳ̤j...";
					next;
					cutin "kafra_01",255;
					break;
				case 2:
					mes "[ d ¾ ]";
					mes "ڷ|VOԾĪzAȪ!";
					close;
				}
				break;
			case 2:
				mes "[ ޲zH ]";
				mes "DH,ڷQڭӭndU{bod¾,]owgܺɩүaڭ̪AȤF!";
				close;
			}
			disablenpc "d ¾#sch02";
			SetCastleData "schg_cas02",9,0;
			mes "[ ޲zH ]";
			mes "d¾wgѶF... LFW|۷Q,Υd¾W";
			close;
		}
		else {
			mes "[ ޲zH ]";
			mes "Md`qq,QnbKa̭,Υd¾?";
			mes "QnΪ,ݭn ^FF000010,000 ^000000";
			next;
			switch(select(":")) {
			case 1:
				if (getgdskilllv(.@GID,10001) == 0) {
					mes "[ ޲zH ]";
					mes "DH,p٨Sd`qqp,ҥH٤නΥd¾,pQnd`qñq,Ƿ|u|ޯत ^FF0000Mdԭq^000000ޯa";
					close;
				}
				if (Zeny < 10000) {
					mes "[ ޲zH ]";
					mes "DH,ASiHΥd¾";
					close;
				}
				set zeny,zeny-10000;
				enablenpc "d ¾#sch02";
				SetCastleData "schg_cas02",9,1;
				mes "[ ޲zH ]";
				mes "\Md`qñqF,zΤF@d¾!";
				next;
				cutin "kafra_01",2;
				mes "[ d ¾ ]";
				mes "zn?ڬO`qӪd¾!ڱN|ܺɩүazA!";
				next;
				cutin "kafra_01",255;
				mes "[ ޲zH ]";
				mes "Ϊd¾N^FF00001 Ӥ몺ɶ^000000bA,ɶFᥲsñq";
				close;
			case 2:
				mes "[ ޲zH ]";
				mes "ڤwgӧAhJF,L]nFW|۷Q,鶱Υd¾W";
				close;
			}
		}
	case 5:
		mes "[ ޲zH ]";
		mes "nڭ̥Ͳ~yn,uQ~ж?";
		mes "ӦaOFڭ̪DH,MݩAa...";
		mes "FA~,䥦HӤJ";
		next;
		mes "[ ޲zH ]";
		mes "|~,qЯSO`N,";
		mes "ҥHFڭ̤|oi,ЮXɶӦ~";
		next;
		switch(select("niJDHж:")) {
		case 1:
			mes "[ ޲zH ]";
			mes "ڱNAAȨ쯦KqD,иڨ,";
			mes "^ӪɭԫUKsYi";
			close2;
			warp "schg_cas02",249,373;
			end;
		case 2:
			mes "[ ޲zH ]";
			mes "Ͳ~@ѥuͲ@...";
			mes "pSYɦ,U@NiӤF";
			mes "ҥHFڭ̤u|oi,ɶqIɶh";
			close;
		}
	}

Onstop:
	stopnpctimer;
	end;

OnStartArena:
	set .@GID,getcharid(2);
	// Lower castle Economy
	set .@Economy,GetCastleData("schg_cas02",2) - 5;
	if (.@Economy < 0) set .@Economy, 0;
	SetCastleData "schg_cas02", 2, .@Economy;
	// Lower Castle Defence
	set .@Defence,GetCastleData("schg_cas02",3) - 5;
	if (.@Defence < 0) set .@Defence, 0;
	SetCastleData "schg_cas02", 3, .@Defence;
	// Set new owner
	SetCastleData "schg_cas02",1, .@GID;
	// Clear castle's data.
	for( set .@i, 4; .@i <= 9; set .@i, .@i+1 )
		SetCastleData "schg_cas02", .@i, 0;
	// Disable Kafra
	disablenpc "d ¾#sch02";

	set .msg,2;
	if (.msg == 1) {
		announce "Ka [" + GetCastleName("schg_cas02") + "] 'woJ'Q [" + getguildname(.@gid) + "] |ҦF",bc_all;
		donpcevent "Manager#sch02_02::Onstart";
	}
	else if (.msg == 2) {
		announce "Ka [" + GetCastleName("schg_cas02") + "] 'woJ'Q [" + getguildname(.@gid) + "] |ҦF",bc_all;
		mapannounce "schg_cas02","RݤwQ}aF",bc_map,"0x00FF00";
		if (agitcheck2()) {
			donpcevent "Manager#sch02_02::Onreset";
			initnpctimer;
		}
		else {
			donpcevent "Manager#sch02_02::Onreset";
			stopnpctimer;
		}
	}
	else if (.msg == 0) {
		announce "Ka [" + GetCastleName("schg_cas02") + "] 'woJ'Q [" + getguildname(.@gid) + "] |ҦF",bc_all;
		donpcevent "Manager#sch02_02::Onreset";
		stopnpctimer;
		end;
	}
	MapRespawnGuildID "schg_cas02",GetCastleData("schg_cas02",1),2;
	GetCastleData "schg_cas02",0,"::OnRecvCastlesc02";
	end;

OnTimer10000:
	donpcevent "Manager#sch02_02::Onchange";
	mapannounce "schg_cas02","bUӾIMmu״_I wnF",bc_map,"0x00FF00";
	end;
}

// Guild Kafra
schg_cas02,131,365,3	script	d ¾#sch02	117,{
	cutin "kafra_01",2;
	set .@GID, GetCastleData("schg_cas02",1);
	if (getcharid(2) == .@GID && getgdskilllv(.@GID,10001)) {
		mes "[d ¾]";
		mes "w{ ^FF0000" + GetGuildName(.@GID) + "^000000 |,";
		mes "dԪA";
		mes "ûbU쨭䬰zAȪ";
		next;
		switch(select("ϥέܮwA:ϥΪŶʪA:ϥΤA:")) {
		case 1:
			if (basicskillcheck() && getskilllv(1) < 6) {
				mes "[d ¾]";
				mes "藍_";
				mes "QnϥέܮwAȪ,Ǫ̪򥻧ޯ൥ŭnF6ťHW";
			}
			else {
				openstorage;
			}
			break;
		case 2:
			mes "[d ¾]";
			mes "лXتaa";
			next;
			switch(select("  -> 200 z:")) {
			case 1:
				if (Zeny < 200) {
					mes "[d ¾]";
					mes "zB,";
					mes "ЦAT{";
					close2;
					cutin "kafra_01",255;
					end;
				}
				set zeny,zeny-200;
				warp "yuno",158,125;
				end;
			case 2:
				cutin "kafra_01",255;
			}
			break;
		case 3:
			if (BaseClass != Job_Merchant) {
				mes "[d ¾]";
				mes "ܩp,";
				mes "OӤHMKK,NvMΪA";
			}
			else if (checkcart() == 1) {
				mes "[d ¾]";
				mes "zwgLF";
			}
			else {
				mes "[d ¾]";
				mes "ϥζOάO 800 ";
				mes "znϥζ?";
				next;
				switch(select("ϥ:")) {
				case 1:
					if (Zeny < 800) {
						mes "[d ¾]";
						mes "zB,";
						mes "ϥζOάO 800 ";
						close2;
						cutin "kafra_01",255;
						end;
					}
					set zeny,zeny-800;
					setcart;
					break;
				case 2:
					break;
				}
			}
			break;
		case 4:
			mes "[d ¾]";
			mes "ڭ̥dԪAȷ|ѧ󧹬AȩMY檺~Ⱥ޲z,UUȦw߫KQϥά̤jؼ";
			mes "P§AϥΥdԪA";
			close2;
			cutin "kafra_01",255;
			end;
		}
		close2;
		cutin "kafra_01",255;
		end;
	}
	else {
		mes "[d ¾]";
		mes "ڤwñqM^FF0000" + GetGuildName(.@GID) + "^000000|A,ШϥΧڭ̨䥦a誺d¾,pKBqШ";
		close2;
		cutin "kafra_01",255;
		end;
	}

OnRecvCastlesc02:
	if (GetCastleData("schg_cas02",1) == 0) {
		monster "schg_cas02",0,0,"x",1117,10;
		monster "schg_cas02",0,0,"dQ",1132,4;
		monster "schg_cas02",0,0,"`WMh",1219,3;
		monster "schg_cas02",0,0,"D",1205,1;
		monster "schg_cas02",0,0,"Ǯ",1216,10;
		monster "schg_cas02",0,0,"",1193,18;
		monster "schg_cas02",0,0,"j]",1269,9;
		monster "schg_cas02",0,0,"F}b",1276,12;
		monster "schg_cas02",0,0,"eH",1208,3;
		monster "schg_cas02",0,0,"RRk",1275,1;
		monster "schg_cas02",0,0,"{Mh",1268,2;
		monster "schg_cas02",0,0,"·t",1272,2;
		monster "schg_cas02",0,0,"u@",1270,4;
	}
	if (GetCastleData("schg_cas02",9) < 1) {
		disablenpc "d ¾#sch02";
	}
	end;
}

schg_cas02,257,369,0	script	#sc02_switch 	111,{
	mes " ";
	mes "ӬYؤp˸m,аݧAnާ@?";
	next;
	switch(select("ާ@:")) {
	case 1:
		warp "schg_cas02",339,79;
		end;
	case 2:
		close;
	}
}

sch_gld,296,247,4	script	woJ#flag_sc02_1::Sc02_Flag	722,{
	set .@GID, GetCastleData("schg_cas02",1);
	if (.@GID == 0) {
		mes "[ qoow а iO ]";
		mes "The Holy Kingdom of";
		mes "Schwaltzvalt declares that";
		mes "one has yet to claim lordship";
		mes "over this stronghold. The one";
		mes "that breaks the Emperium will";
		mes "be recognized as its new owner.";
		close;
	}
	else {
		if (getcharid(2) == .@GID) {
			mes "[ TGn ]";
			mes "i̭...";
			mes "An^A WAɨ?";
			next;
			switch(select("^쯵Ka:")) {
			case 1:
				set .@GID, GetCastleData("schg_cas02",1);
				if (getcharid(2) == .@GID) {
					warp "schg_cas02",136,188;
					end;
				}
				close;
			case 2:
				close;
			}
		}
		mes "[ qoow а iO ]";
		mes " ";
		mes "1. ھڳo̪,qoow аO";
		mes "o̳Q{w ^FF0000" + GetGuildName(.@GID) + "^000000|";
		mes "p";
		mes " ";
		mes "2. ^FF0000" + GetGuildName(.@GID) + "^000000 |DHO";
		mes "@@^FF0000" + GetGuildMaster(.@GID) + "^000000,L׬O";
		mes "@@oƱN";
		mes " ";
		mes "ЧA|_zC,ۤvWAa";
		close;
	}

OnRecvCastlesc02:
	FlagEmblem GetCastleData("schg_cas02",1);
	end;
}

sch_gld,280,247,4	duplicate(Sc02_Flag)	woJ#flag_sc02_2	722